var mongoose=require('mongoose');
var Post=mongoose.model('Post',{
    title:String,
    authors:[String],
    comments:[
        {
            content:String,
            like:Number
        }
    ]
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');

var title='post12';
Post.update({title:title},{
    comments:[
        {
            content:'c1',
            like:0
        },
        {
            content:'c2',
            like:0
        }
    ]
},{upsert:true},(err,r)=>{
    console.log('Update:',err,r);

    Post.update({title:title},{
        $inc:{
            'comments.0.like':10,
            'comments.1.like':20
        }
    },(e,r)=>{
        console.log('定位操作1：',e,r);

        Post.find({title:title},(e,r)=>{
            console.log('Find:\n',e);
            console.log(JSON.stringify(r,null,2));
            process.exit(1);
        });
    });

});


/*
 * .点号数组定位操作，访问数组点号指定的下标元素
 *
 * */





